﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using spbtzb;

public partial class Main : System.Web.UI.Page
{
    //protected string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='E://spbtzb.mdb';";
    protected string strConnection = spbtzb.ConString.ConnString;
    protected void Page_Load(object sender, EventArgs e)
    {
        BindControl();
        BindParts("LLYJ");
    }

    protected void BindControl()
    {
        rpNotice.DataSource = AccessHelper.ExecuteDataTable(strConnection, CommandType.Text,
        "SELECT TOP 5 ID, Title, CreateTime FROM Contents WHERE typecode = 'WZGG' Order By CreateTime DESC ,ID DESC");
        rpNotice.DataBind();

        Repeater1.DataSource = AccessHelper.ExecuteDataTable(strConnection, CommandType.Text,
        "SELECT TOP 10 ID, Title, CreateTime FROM Contents WHERE typecode = 'WZGG' Order By CreateTime DESC ,ID DESC");
        Repeater1.DataBind();
    }
    protected string ConvertTime(object obj)
    {
        if (obj is Nullable)
            return "[]";
        try
        {
            DateTime dt = DateTime.Parse(obj.ToString());
            return "[" + dt.Year.ToString() + "-" + dt.Month.ToString() + "-" + dt.Day.ToString() + "]";
        }
        catch { }
        return "[]";

    }

    protected void rpParts_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater rpList = (Repeater)e.Item.FindControl("rpList");
            DataRowView dv = (DataRowView)e.Item.DataItem;

            if (rpList != null)
            {
                rpList.DataSource = AccessHelper.ExecuteDataTable(strConnection, CommandType.Text,
                            "SELECT TOP 5 ID, Title, CreateTime FROM Contents WHERE TypeCode = '" + dv["TypeCode"].ToString() + "'");
                rpList.DataBind();
            }
        }
    }
    protected void BindParts(string parentType)
    {
        DataTable dt = AccessHelper.ExecuteDataTable(strConnection, CommandType.Text,
                            "SELECT ID, TypeCode, TypeName FROM ContentType WHERE ParentType = '" + parentType + "'");

        rpParts.DataSource = dt;
        rpParts.DataBind();

    }
}
